//
//  ViewController.m
//  DEMO
//
//  Created by J on 16/3/4.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"
#import "CustomButton.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button;

@property (weak, nonatomic) IBOutlet UIView *buttonView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.button setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
    [self.button setImage:[UIImage imageNamed:@"4"] forState:UIControlStateHighlighted];

    [self.button setTitle:@"icon" forState:UIControlStateNormal];
    self.button.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [self.buttonView addGestureRecognizer:tap];
}

- (void)tap:(UITapGestureRecognizer*)tap{
    CABasicAnimation * rotationAnimation = [CABasicAnimation animation];
    rotationAnimation.keyPath=@"transform.rotation.y";
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 0.8;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 0;
    [self.buttonView.layer addAnimation:rotationAnimation forKey:nil];

    
}
- (IBAction)button:(CustomButton *)sender {
    CABasicAnimation * rotationAnimation = [CABasicAnimation animation];
    rotationAnimation.keyPath=@"transform.rotation.y";
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 0.8;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 0;
    [sender.layer addAnimation:rotationAnimation forKey:nil];
    
}

@end
